home *** CD-ROM | disk | FTP | other *** search
- Public Class ListComboBoxBindingForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents txtFirstName As System.Windows.Forms.TextBox
- Friend WithEvents lblRecord As System.Windows.Forms.Label
- Friend WithEvents btnPrevious As System.Windows.Forms.Button
- Friend WithEvents btnNext As System.Windows.Forms.Button
- Friend WithEvents btnLast As System.Windows.Forms.Button
- Friend WithEvents btnFirst As System.Windows.Forms.Button
- Friend WithEvents Label2 As System.Windows.Forms.Label
- Friend WithEvents txtLastName As System.Windows.Forms.TextBox
- Friend WithEvents Label3 As System.Windows.Forms.Label
- Friend WithEvents txtBirthDate As System.Windows.Forms.TextBox
- Friend WithEvents chkPartTime As System.Windows.Forms.CheckBox
- Friend WithEvents Label4 As System.Windows.Forms.Label
- Friend WithEvents cboDepartments As System.Windows.Forms.ComboBox
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.txtBirthDate = New System.Windows.Forms.TextBox()
- Me.Label2 = New System.Windows.Forms.Label()
- Me.Label3 = New System.Windows.Forms.Label()
- Me.btnLast = New System.Windows.Forms.Button()
- Me.lblRecord = New System.Windows.Forms.Label()
- Me.btnNext = New System.Windows.Forms.Button()
- Me.cboDepartments = New System.Windows.Forms.ComboBox()
- Me.chkPartTime = New System.Windows.Forms.CheckBox()
- Me.txtFirstName = New System.Windows.Forms.TextBox()
- Me.btnPrevious = New System.Windows.Forms.Button()
- Me.Label4 = New System.Windows.Forms.Label()
- Me.txtLastName = New System.Windows.Forms.TextBox()
- Me.Label1 = New System.Windows.Forms.Label()
- Me.btnFirst = New System.Windows.Forms.Button()
- Me.SuspendLayout()
- '
- 'txtBirthDate
- '
- Me.txtBirthDate.Location = New System.Drawing.Point(16, 112)
- Me.txtBirthDate.Name = "txtBirthDate"
- Me.txtBirthDate.Size = New System.Drawing.Size(192, 24)
- Me.txtBirthDate.TabIndex = 5
- Me.txtBirthDate.Text = ""
- '
- 'Label2
- '
- Me.Label2.Location = New System.Drawing.Point(232, 24)
- Me.Label2.Name = "Label2"
- Me.Label2.Size = New System.Drawing.Size(168, 24)
- Me.Label2.TabIndex = 2
- Me.Label2.Text = "Last Name"
- '
- 'Label3
- '
- Me.Label3.Location = New System.Drawing.Point(16, 88)
- Me.Label3.Name = "Label3"
- Me.Label3.Size = New System.Drawing.Size(168, 24)
- Me.Label3.TabIndex = 4
- Me.Label3.Text = "Birth Date"
- '
- 'btnLast
- '
- Me.btnLast.Location = New System.Drawing.Point(328, 224)
- Me.btnLast.Name = "btnLast"
- Me.btnLast.Size = New System.Drawing.Size(48, 32)
- Me.btnLast.TabIndex = 11
- Me.btnLast.Text = ">>"
- '
- 'lblRecord
- '
- Me.lblRecord.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
- Me.lblRecord.Location = New System.Drawing.Point(192, 224)
- Me.lblRecord.Name = "lblRecord"
- Me.lblRecord.Size = New System.Drawing.Size(88, 32)
- Me.lblRecord.TabIndex = 9
- Me.lblRecord.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
- '
- 'btnNext
- '
- Me.btnNext.Location = New System.Drawing.Point(280, 224)
- Me.btnNext.Name = "btnNext"
- Me.btnNext.Size = New System.Drawing.Size(48, 32)
- Me.btnNext.TabIndex = 10
- Me.btnNext.Text = ">"
- '
- 'cboDepartments
- '
- Me.cboDepartments.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
- Me.cboDepartments.DropDownWidth = 192
- Me.cboDepartments.Location = New System.Drawing.Point(16, 176)
- Me.cboDepartments.Name = "cboDepartments"
- Me.cboDepartments.Size = New System.Drawing.Size(192, 26)
- Me.cboDepartments.TabIndex = 13
- '
- 'chkPartTime
- '
- Me.chkPartTime.Location = New System.Drawing.Point(232, 112)
- Me.chkPartTime.Name = "chkPartTime"
- Me.chkPartTime.Size = New System.Drawing.Size(176, 16)
- Me.chkPartTime.TabIndex = 6
- Me.chkPartTime.Text = "PartTime Employee"
- '
- 'txtFirstName
- '
- Me.txtFirstName.Location = New System.Drawing.Point(16, 48)
- Me.txtFirstName.Name = "txtFirstName"
- Me.txtFirstName.Size = New System.Drawing.Size(192, 24)
- Me.txtFirstName.TabIndex = 1
- Me.txtFirstName.Text = ""
- '
- 'btnPrevious
- '
- Me.btnPrevious.Location = New System.Drawing.Point(144, 224)
- Me.btnPrevious.Name = "btnPrevious"
- Me.btnPrevious.Size = New System.Drawing.Size(48, 32)
- Me.btnPrevious.TabIndex = 8
- Me.btnPrevious.Text = "<"
- '
- 'Label4
- '
- Me.Label4.Location = New System.Drawing.Point(16, 152)
- Me.Label4.Name = "Label4"
- Me.Label4.Size = New System.Drawing.Size(160, 24)
- Me.Label4.TabIndex = 12
- Me.Label4.Text = "Department"
- '
- 'txtLastName
- '
- Me.txtLastName.Location = New System.Drawing.Point(232, 48)
- Me.txtLastName.Name = "txtLastName"
- Me.txtLastName.Size = New System.Drawing.Size(192, 24)
- Me.txtLastName.TabIndex = 3
- Me.txtLastName.Text = ""
- '
- 'Label1
- '
- Me.Label1.Location = New System.Drawing.Point(16, 24)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(168, 24)
- Me.Label1.TabIndex = 0
- Me.Label1.Text = "First Name"
- '
- 'btnFirst
- '
- Me.btnFirst.Location = New System.Drawing.Point(96, 224)
- Me.btnFirst.Name = "btnFirst"
- Me.btnFirst.Size = New System.Drawing.Size(48, 32)
- Me.btnFirst.TabIndex = 7
- Me.btnFirst.Text = "<<"
- '
- 'ListComboBoxBindingForm
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
- Me.ClientSize = New System.Drawing.Size(456, 269)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cboDepartments, Me.Label4, Me.chkPartTime, Me.Label3, Me.txtBirthDate, Me.Label2, Me.txtLastName, Me.lblRecord, Me.btnLast, Me.btnNext, Me.btnPrevious, Me.btnFirst, Me.txtFirstName, Me.Label1})
- Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Name = "ListComboBoxBindingForm"
- Me.Text = "Bound ComboBox control"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- ' create two arrays of objects that will work as data sources
-
- Dim employees() As Employee = {New Employee("Joe", "Doe", #1/3/1960#, , 1), _
- New Employee("Robert", "Smith", #11/23/1962#, , 2), _
- New Employee("Ann", "Ross", #2/5/1965#, True, 3)}
-
- Dim departments() As Department = {New Department("Sales", 1), _
- New Department("Tech Support", 2), New Department("Marketing", 3)}
-
- Dim WithEvents bmb As BindingManagerBase
-
- ' initialize binding when the form loads
-
- Private Sub SimpleBindingForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- InitializeBinding()
- End Sub
-
- Sub InitializeBinding()
- ' Load the Departments in the combobox control.
- cboDepartments.DisplayMember = "Name"
- cboDepartments.ValueMember = "ID"
- cboDepartments.DataSource = departments
-
- ' Create the Binding object for each bound field.
- txtFirstName.DataBindings.Add("Text", employees, "FirstName")
- txtLastName.DataBindings.Add("Text", employees, "LastName")
- txtBirthDate.DataBindings.Add("Text", employees, "BirthDate")
- chkPartTime.DataBindings.Add("Checked", employees, "PartTimeEmployee")
- cboDepartments.DataBindings.Add("SelectedValue", employees, "DepartmentID")
-
- ' Save a reference to the BindingManagerBase object.
- bmb = Me.BindingContext(employees)
- ' Force a refresh of buttons
- bmb.Position = bmb.Count
- bmb.Position = 0
- End Sub
-
- ' navigational buttons
-
- Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
- bmb.Position = 0
- End Sub
-
- Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
- bmb.Position -= 1
- End Sub
-
- Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
- bmb.Position += 1
- End Sub
-
- Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
- bmb.Position = bmb.Count - 1
- End Sub
-
- ' Display current position in label.
- Private Sub bmb_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bmb.PositionChanged
- lblRecord.Text = String.Format("{0} of {1}", bmb.Position + 1, bmb.Count)
- ' Enable/disable buttons.
- btnFirst.Enabled = (bmb.Position > 0)
- btnPrevious.Enabled = (bmb.Position > 0)
- btnNext.Enabled = (bmb.Position < bmb.Count - 1)
- btnLast.Enabled = (bmb.Position < bmb.Count - 1)
- End Sub
- End Class
-